package com.yunupmall.controller.amdin;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yunupmall.api.fordVO.FordSpecsPo;
import com.yunupmall.api.fordVO.SpecsVo;
import com.yunupmall.api.fordentity.Specs;
import com.yunupmall.api.po.SpecsPo;
import com.yunupmall.service.admin.service.SpecsService;
import com.yunupmall.uits.Result;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@AllArgsConstructor
@RequestMapping(value = "/specs")
public class SpecsController {
    private final SpecsService specsService;
    private final Result result;

    /**
     * 添加规格
     * @param
     * @return
     */
    @PostMapping(value = "/addSpecsList", produces = "application/json;charset=UTF-8")
    public Result<String> addSpecsData(@RequestBody List<SpecsVo> specsData) {
        try {
          return result.ok(specsService.AddSpecs(specsData));
        }catch (Exception e) {
           return result.error();
        }
    }

    //分页，类别ID下的规格
    @PostMapping("/page")
    public Result<List<SpecsPo>> setID(@RequestBody FordSpecsPo fordSpecsPo) {
        try {
            return result.ok(specsService.pageId(fordSpecsPo));
        }catch (Exception e) {
            return result.error();
        }
    }

    /**
     * 通过ID获取数据
     * @param kindId
     * @return
     */
    @GetMapping("/byid")
    public Result<List<SpecsPo>> byid(@RequestParam Integer kindId) {
        try {
            return result.ok(specsService.byid(kindId));
        }catch (Exception e) {
            return result.error();
        }
    }

    //删除规格
    @GetMapping("/delete")
    public Result<String> delete(@RequestParam("id") Integer ids) {
        try {
            return result.ok(specsService.deleteData(ids));
        }catch (Exception e) {
            return result.error(e.getMessage());
        }
    }
    //获得未处理数据集
    @PostMapping("/getList")
    public Result<List<Specs>> getList(@RequestBody Specs specs) {
        try {
            return result.ok(specsService.getList(specs));
        }catch (Exception e) {
            return result.error(e.getMessage());
        }
    }
}
